Install_Golang_Environment(){

# 判断是否已经安装GOLANG环境
type go >& /dev/null
if [ $? -eq 0 ]
then
    echo "你已经安装golang环境"
    echo `go version`
    return 0
fi
echo "----------------------------------"
echo "选择安装版本："
echo "1) 1.11"
echo "2) 1.10.4"
echo "3) 1.9.7"
echo "4) 1.8.7"
echo "----------------------------------"
read -p "输入安装版本编号(默认1):" version
if [ -z $version ]
then
GO_VERSION=1.11
else
    case $version in
    1)
    GO_VERSION=1.11
    ;;
    2)
    GO_VERSION=1.10.4
    ;;
    3)
    GO_VERSION=1.9.7
    ;;
    4)
    GO_VERSION=1.8.7
    ;;
    esac
fi

# 置版本号变量结束 开始下载包并配置环境变量
sudo yum install -y git wget gcc gcc-c++
GO_URL="https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"

# 配置程序安装位置
read -p "输入程序安装目录GOROOT(默认 /usr/local)：" GOROOT

if [ -z $GOROOT ];then
    GOROOT="/usr/local"
fi

# 判断安装目录是否存在
if [ ! -d $GOROOT ];then
mkdir -p $GOROOT
fi

wget -c -P /tmp $GO_URL && tar zxf /tmp/go${GO_VERSION}.linux-amd64.tar.gz -C /tmp && sudo mv /tmp/go $GOROOT
# 输入GOPATH目录
read -p "输入GOPATH目录(默认 $HOME/go)：" GOPATH

if [ -z $GOPATH ] || [ ! -d $GOPATH ]
then
    GOPATH='$HOME/go'
fi


# 检测shell 配置环境变量到shell配置文件中
if [ $SHELL == "/bin/bash" ]
then
    if [ $(id -u) == "0" ]; then
        config="/etc/profile"
    fi
    config="$HOME/.bashrc"
else
    config="$HOME/.zshrc"
fi
echo '# go environment config' >> $config
echo "export GOROOT=$GOROOT/go  #go安装路径" >> $config
echo 'export GOBIN=$GOROOT/bin  #go可执行程序文件路径' >> $config
echo "export GOPATH=$GOPATH  #GOPATH 请自定义"  >> $config
echo 'export PATH=$PATH:$GOBIN' >> $config
source $config

# 环境安装完成
go version
echo "环境变量配置成功！请执行 source $config 确保配置生效"
}

Install_Web_FrameWork(){
    while true
    do
        echo "----------------------------------"
        echo "选择需要安装的框架编号："
        echo "1) Beego"
        echo "2) Gin"
        echo "3) Echo"
        echo "4) Revel"
        echo "5) Faygo"
        echo "6) Macaron"
        echo "7) 返回上级"
        echo "8) 退出程序"
        echo "----------------------------------"
        read -p "输入安装版本编号(默认1):" framework

        echo "下载或者编译安装过程可能是一个漫长的过程，需要你的耐心等待....."
        
        if [ -z $framework ]
        then
            framework=1
        fi

        case $framework in
            1)
                echo "正在下载框架： github.com/astaxie/beego"
                gopm get -g github.com/astaxie/beego
                echo "正在下载并构建配套工具： github.com/beego/bee"
                go get github.com/beego/bee
            ;;
            2)
                echo "正在下载框架： github.com/gin-gonic/gin"
                gopm get -g github.com/gin-gonic/gin
            ;;
            3)
                echo "正在下载框架： github.com/labstack/echo"
                gopm get -g github.com/labstack/echo
            ;;
            4)
                echo "正在下载框架： github.com/revel/cmd/revel"
                gopm get -g github.com/revel/cmd/revel
            ;;
            5)
                echo "正在下载配套工具： github.com/henrylee2cn/fay"
                gopm get -g github.com/henrylee2cn/fay
            ;;
            6)
                echo "正在下载框架： gopkg.in/macaron.v1"
                gopm get -g gopkg.in/macaron.v1
            ;;
            7)
                break
            ;;
            8)
                echo "程序结束"
                exit 1
            ;;
        esac
        echo "安装结束,请自行检测是否安装成功！"
    done
}

Install_Package(){
    while true
    do
        echo "----------------------------------"
        echo "选择需要安装的类型编号："
        echo "1) 第三方包(手动输入包地址)"
        echo "2) 数据库相关"
        echo "3) orm框架"
        echo "4) 返回上级"
        echo "5) 退出程序"
        echo "----------------------------------"
        read -p "输入安装版本编号(默认1):" func

        if [ -z $func ]
        then
            func=1
        fi

        case $func in
            1)
                read -p "请输入包地址(示例: github.com/gpmgo/gopm)：" package
                echo "正在安装: $package ..."
                gopm get -g $package
                echo "安装结束,请自行检测是否安装成功！"
            ;;
            2)
                Install_DB
            ;;
            3)
                Install_orm
            ;;
            4)
                break
            ;;
            5)
                echo "操作取消"
                exit
            ;;
        esac
    done
}
Install_DB(){
    echo "----------------------------------"
    echo "选择需要安装的包编号："
    echo "1) mysql驱动"
    echo "2) sqlite驱动"
    echo "3) postgresql驱动"
    echo "4) redis驱动"
    echo "5) memcache驱动"
    echo "6) MongoDB驱动"
    echo "----------------------------------"
    read -p "输入安装版本编号(默认1):" dbc

    if [ -z $dbc ]
    then
        dbc=1
    fi

    case $dbc in
        1)
            echo "正在下载驱动： github.com/go-sql-driver/mysql"
            gopm get -g github.com/go-sql-driver/mysql
        ;;
        2)
            echo "正在下载驱动：github.com/mattn/go-sqlite3"
            gopm get -g github.com/mattn/go-sqlite3
        ;;
        3)
            echo "正在下载驱动：github.com/lib/pq"
            gopm get -g github.com/lib/pq
        ;;
        4)
            echo "正在下载驱动：github.com/gomodule/redigo/redis"
            gopm get -g github.com/gomodule/redigo/redis
        ;;
        5)
            echo "正在下载驱动：github.com/bradfitz/gomemcache/memcache"
            gopm get -g github.com/bradfitz/gomemcache/memcache
        ;;
        6)
            echo "正在下载驱动：gopkg.in/mgo.v2"
            gopm get -g gopkg.in/mgo.v2
        ;;
    esac
    echo "安装结束,请自行检测是否安装成功！"
}
Install_orm(){
    echo "----------------------------------"
    echo "选择需要安装的包编号："
    echo "1) xorm"
    echo "2) gorm"
    echo "----------------------------------"
    read -p "输入安装版本编号(默认1):" orm

    if [ -z $orm ]
    then
        orm=1
    fi

    case $orm in
        1)
            echo "正在下载驱动： github.com/go-xorm/xorm"
            gopm get -g github.com/go-xorm/xorm
        ;;
        2)
            echo "正在下载驱动：github.com/jinzhu/gorm"
            gopm get -g github.com/jinzhu/gorm
        ;;
    esac
    echo "安装结束,请自行检测是否安装成功！"
}

Install_gopm(){
    type gopm >& /dev/null
    if [ $? -eq 0 ]
    then
        echo -e "\n程序已安装！ 执行 gopm -h 查看帮助手册\n"
    else
        read -p "是否安装？(y/N):" continue
        if [ -z $continue ] || [ $continue == "N" ] || [ $continue == "n" ]
        then
            echo "程序已取消安装"
        else
            go get -u github.com/gpmgo/gopm
            echo -e "\n安装完成！执行 gopm -h 查看帮助手\n"
        fi
    fi
}